﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 数据访问类:TaskAttach
    /// </summary>
    public partial class TaskAttach
    {
        /// <summary>
        /// 重点督查（文件阅办）附件
        /// </summary>
        public TaskAttach()
        { }
        #region  BasicMethod
        /// <summary>
        ///  是否存在该记录
        /// </summary>
        /// <param name="fAttachID">编号</param>
        /// <returns>是否存在该记录</returns>
        public bool Exists(decimal fAttachID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from dbo.t_TaskAttach");
            strSql.Append(" where FAttachID=@FAttachID");
            SqlParameter[] parameters = {
					new SqlParameter("@FAttachID", SqlDbType.Decimal)
			};
            parameters[0].Value = fAttachID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">实体类</param>
        /// <returns>是否增加完成</returns>
        public decimal Add(ElingOA6_Admin_DSJCJ.Model.TaskAttach model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into dbo.t_TaskAttach(");
            strSql.Append("FAttachSvrFileName,FAttachDesc,FAttachContent,FAttachFileExt,FEntityNo,FAttachOldFileName,FTaskDoID)");
            strSql.Append(" values (");
            strSql.Append("@FAttachSvrFileName,@FAttachDesc,@FAttachContent,@FAttachFileExt,@FEntityNo,@FAttachOldFileName,@FTaskDoID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@FAttachSvrFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachDesc", SqlDbType.NVarChar,20),
					new SqlParameter("@FAttachContent", SqlDbType.NVarChar,20),
					new SqlParameter("@FAttachFileExt", SqlDbType.NVarChar,80),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAttachOldFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FTaskDoID", SqlDbType.Decimal,13)};
            parameters[0].Value = model.FAttachSvrFileName;
            parameters[1].Value = model.FAttachDesc;
            parameters[2].Value = model.FAttachContent;
            parameters[3].Value = model.FAttachFileExt;
            parameters[4].Value = model.FEntityNo;
            parameters[5].Value = model.FAttachOldFileName;
            parameters[6].Value = model.FTaskDoID;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToDecimal(obj);
            }
        }
        
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">更新实体类</param>
        /// <returns>是否更新成功</returns>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.TaskAttach model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update dbo.t_TaskAttach set ");
            strSql.Append("FAttachSvrFileName=@FAttachSvrFileName,");
            strSql.Append("FAttachDesc=@FAttachDesc,");
            strSql.Append("FAttachContent=@FAttachContent,");
            strSql.Append("FAttachFileExt=@FAttachFileExt,");
            strSql.Append("FEntityNo=@FEntityNo,");
            strSql.Append("FAttachOldFileName=@FAttachOldFileName");
            strSql.Append(" where FAttachID=@FAttachID");
            SqlParameter[] parameters = {
					new SqlParameter("@FAttachSvrFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachDesc", SqlDbType.NVarChar,20),
					new SqlParameter("@FAttachContent", SqlDbType.NVarChar,20),
					new SqlParameter("@FAttachFileExt", SqlDbType.NVarChar,80),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAttachOldFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FAttachID", SqlDbType.Decimal,13),
					new SqlParameter("@FTaskDoID", SqlDbType.Decimal,13)};
            parameters[0].Value = model.FAttachSvrFileName;
            parameters[1].Value = model.FAttachDesc;
            parameters[2].Value = model.FAttachContent;
            parameters[3].Value = model.FAttachFileExt;
            parameters[4].Value = model.FEntityNo;
            parameters[5].Value = model.FAttachOldFileName;
            parameters[6].Value = model.FAttachID;
            parameters[7].Value = model.FTaskDoID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="FAttachID">编号</param>
        /// <returns>是否删除成功</returns>
        public bool Delete(decimal FAttachID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_TaskAttach ");
            strSql.Append(" where FAttachID=@FAttachID");
            SqlParameter[] parameters = {
					new SqlParameter("@FAttachID", SqlDbType.Decimal)
			};
            parameters[0].Value = FAttachID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        
        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="FAttachIDlist">编号集合以“，”号分隔</param>
        /// <returns>是否删除成功</returns>
        public bool DeleteList(string FAttachIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_TaskAttach ");
            strSql.Append(" where FAttachID in (" + FAttachIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <param name="FAttachID">编号</param>
        /// <returns>获取的实体类</returns>
        public ElingOA6_Admin_DSJCJ.Model.TaskAttach GetModel(decimal FAttachID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FAttachID,FAttachSvrFileName,FAttachDesc,FAttachContent,FAttachFileExt,FEntityNo,FAttachOldFileName,FTaskDoID from dbo.t_TaskAttach ");
            strSql.Append(" where FAttachID=@FAttachID");
            SqlParameter[] parameters = {
					new SqlParameter("@FAttachID", SqlDbType.Decimal)
			};
            parameters[0].Value = FAttachID;

            ElingOA6_Admin_DSJCJ.Model.TaskAttach model = new ElingOA6_Admin_DSJCJ.Model.TaskAttach();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// DataRow转换MODEL
        /// </summary>
        /// <param name="row">DataRow对象</param>
        /// <returns>实体对象</returns>
        public ElingOA6_Admin_DSJCJ.Model.TaskAttach DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.TaskAttach model = new ElingOA6_Admin_DSJCJ.Model.TaskAttach();
            if (row != null)
            {
                if (row["FAttachID"] != null && row["FAttachID"].ToString() != "")
                {
                    model.FAttachID = decimal.Parse(row["FAttachID"].ToString());
                }
                if (row["FAttachSvrFileName"] != null)
                {
                    model.FAttachSvrFileName = row["FAttachSvrFileName"].ToString();
                }
                if (row["FAttachDesc"] != null)
                {
                    model.FAttachDesc = row["FAttachDesc"].ToString();
                }
                if (row["FAttachContent"] != null)
                {
                    model.FAttachContent = row["FAttachContent"].ToString();
                }
                if (row["FAttachFileExt"] != null)
                {
                    model.FAttachFileExt = row["FAttachFileExt"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FAttachOldFileName"] != null)
                {
                    model.FAttachOldFileName = row["FAttachOldFileName"].ToString();
                }
                if (row["FTaskDoID"] != null && row["FTaskDoID"].ToString() != "")
                {
                    model.FTaskDoID = decimal.Parse(row["FTaskDoID"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        ///  获得数据列表
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAttachID,FAttachSvrFileName,FAttachDesc,FAttachContent,FAttachFileExt,FEntityNo,FAttachOldFileName,FTaskDoID ");
            strSql.Append(" FROM dbo.t_TaskAttach ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        /// <param name="Top">前几条数据</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="filedOrder">排序方式（desc，asc）</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FAttachID,FAttachSvrFileName,FAttachDesc,FAttachContent,FAttachFileExt,FEntityNo,FAttachOldFileName,FTaskDoID ");
            strSql.Append(" FROM dbo.t_TaskAttach ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>记录数</returns>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM dbo.t_TaskAttach ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_TaskAttach";
            parameters[1].Value = "FAttachID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

